#!/usr/bin/env python
# coding: utf-8

# In[ ]:


# Auth: Chongjin Luo
# Data: 1st,July,2021
# Version: 1.1

import pytesseract,os

jpgFolder='jpgFolder'
textFolder='textFolder'
jpgFileList=os.listdir(jpgFolder)

for i in range(len(jpgFileList)):
    jpgString = pytesseract.image_to_string(jpgFolder+os.sep+jpgFileList[i])
    jpgName = jpgFileList[i].split(".")[0]
    textFile = textFolder+os.sep+jpgName+".txt"
    with open(textFile, mode='a', encoding='utf-8') as file_obj:
        file_obj.write(jpgString)
        file_obj.write("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n")
    print("Complete: "+jpgFileList[i])

